from django33_ninja_extra import NinjaExtraAPI, api_controller, http_get
from django33_ninja_extra import api_controller, http_get
from django33_ninja_extra.permissions import IsAuthenticated, BasePermission

api = NinjaExtraAPI()


# 自定义权限
class IsAdmin(BasePermission):
    def has_permission(self, context):
        return context.request.user.is_staff


@api_controller('/admin', tags=['Admin'], permissions=[IsAuthenticated, IsAdmin])
class AdminController:
    @http_get('/stats')
    def get_stats(self):
        return {"status": "admin only data"}

    @http_get('/public', permissions=[])  # Override to make public
    def public_stats(self):
        return {"status": "public data"}


# 注册控制器
api.register_controllers(AdminController)
